import pageRoutes from '../../config/router.config';

function pathExtend(routes) {
  if (routes instanceof Array) {
    let arr = {};
    routes.forEach(r => {
      const hasPath = Object.prototype.hasOwnProperty.call(r, 'path');
      const hasRoutes = Object.prototype.hasOwnProperty.call(r, 'routes');
      const hasExtendInfo = Object.prototype.hasOwnProperty.call(r, 'extendInfo');
      if (hasRoutes) {
        const children = pathExtend(r.routes);
        arr = Object.assign({}, arr, children);
      } else if (hasPath && hasExtendInfo) {
        arr[r.path] = r.extendInfo;
      }
    });
    return arr;
  }
  return {};
}

export default path => {
  const infos = pathExtend(pageRoutes);
  return infos[path];
};
